package com.linkhub.oms.admin.modules.logistic.rules.strategy.impl;

import com.linkhub.oms.admin.modules.logistic.rules.domain.ChannelRuleMatchRequest;
import com.linkhub.oms.admin.modules.logistic.rules.strategy.ChannelRuleMatchStrategy;
import com.linkhub.oms.common.enums.IEnumConvert;
import com.linkhub.oms.common.enums.logistic.ProductCountLimitEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @Description: ProductCountLimit
 * @Author: echo
 * @Date: 2024/6/1 17:00
 * @Version: 1.0
 */
@Slf4j
@Service
@Order(value = 2)
public class ProductCountLimit extends BaseChannelRuleMatchStrategy implements ChannelRuleMatchStrategy {

    @Override
    public boolean match(ChannelRuleMatchRequest request) {
        String countryCode = request.acquireOrderCountryCode();
        ProductCountLimitEnum productCountLimit = IEnumConvert.valueOf(countryCode, ProductCountLimitEnum.class);
        if (Objects.isNull(productCountLimit)) {
            log.info("ProductCountLimit skip,  key=[{}]", countryCode);
            return true;
        }

        return request.acquireOrderProductQuantity() < productCountLimit.getCount();
    }
}
